package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.groupfifteen.entity.SysDictTypeEntity;
import com.groupfifteen.entity.SysUserEntity;
import com.groupfifteen.service.SysUserService;
import com.groupfifteen.vo.SysUserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("sysuser/info")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/query")
    public IPage Query(@RequestBody SysUserVo sysUserVo) {

        SysUserEntity sysUserEntity = new SysUserEntity();
        sysUserEntity.setId(sysUserVo.getId());
        sysUserEntity.setUserName(sysUserVo.getUserName());
        sysUserEntity.setPassword(sysUserVo.getPassword());

        IPage<SysUserEntity> page = sysUserService.Query(sysUserEntity,1,10);
        return page;
    }

    @PostMapping("addsysuser")
    public String AddSysUser(@RequestBody SysUserEntity sysUserEntity) {
        Integer result = sysUserService.AddSysUser(sysUserEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @DeleteMapping("/deletesysuser/{userId}")
    public String DeleteSysUser(@PathVariable("userId") Integer userId) {
        Integer result = sysUserService.DeleteSysUser(userId);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/getsysuser/{userId}")
    public SysUserEntity GetSysUser(@PathVariable("userId") Integer userId) {
     SysUserEntity result = sysUserService.GetSysUser(userId);
     if (result != null) {
         return result;
     } else {
         return null;
     }
    }

    @PutMapping("/updatesysuser/{id}")
    public String UpdateSysuser(@PathVariable("id")long id,@RequestBody SysUserEntity sysUserEntity) {
        sysUserEntity.setId(id);
        Integer result = sysUserService.UpdateSysUser(sysUserEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @PostMapping("getinfo")
    public String Getinfo() {
        return "success";
    }



}
